package it.asvp.asvp_portal.service.util;

import it.asvp.asvp_portal.asvp_util.enumerative.Role;
import it.asvp.asvp_portal.data.entity.member.MemberAccount;

import java.util.Collection;
import java.util.HashSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@SuppressWarnings("serial")
public class UserDetailsImpl implements UserDetails{
	
	private MemberAccount memberAccount;
	Collection<GrantedAuthority> grantedAuthorities;
	 
	public UserDetailsImpl(MemberAccount memberAccount){
		
		this.memberAccount=memberAccount;		
		Role role=memberAccount.getRole();
		GrantedAuthority gA=new GrantedAuthorityImpl(role.name());
		Collection<GrantedAuthority> grantedAuthorities=new HashSet<GrantedAuthority>();
		grantedAuthorities.add(gA);
		this.grantedAuthorities=grantedAuthorities;
	}
	
	public Collection<GrantedAuthority> getAuthorities() {
		return grantedAuthorities;
	}
	
	public void setAuthorities(Collection<GrantedAuthority> authorities) {
		this.grantedAuthorities = authorities;
	}
	
	public String getPassword() {
		return memberAccount.getPassword();
	}
	
	public void setPassword(String password) {
		this.memberAccount.setPassword(password);
	}
	
	public String getUsername() {
		return this.memberAccount.getLogin();
	}
	
	public void setUsername(String username) {
		this.memberAccount.setLogin(username);
	}
	
	public boolean isEnabled() {
		return this.memberAccount.isEnabled();
	}
	
	public void setEnabled(boolean enabled) {
		this.memberAccount.setEnabled(enabled);
	}
	
	public boolean isAccountNonExpired() {
		return true;
	}
	
	public boolean isAccountNonLocked() {
		return true;
	}
	
 	public boolean isCredentialsNonExpired() {
        return true;
	}
	 
	

}
